package com.study.firstline

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.study.firstline.base.BaseActivity
import kotlinx.android.synthetic.main.activity_second.*

class SecondActivity : BaseActivity() {

    /**
     * 写一个静态方法，第一个Activity调用
     */
    companion object{
        fun actionStart(context:Context,data1:String,data2:String){
            /*val intent=Intent(context,SecondActivity::class.java);
            intent.putExtra("param1",data1);
            intent.putExtra("param2", data2);
            context.startActivity(intent);*/
            // 使用apply简便写法
            val intent=Intent(context,SecondActivity::class.java).apply {
                putExtra("param1",data1);
                putExtra("param2", data2);
            }
            context.startActivity(intent);
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second)

        // 接收第一个activity的值
        val stringExtra = intent.getStringExtra("data")

        // 给第一个Activity返回值
        ac2_btn1.setOnClickListener{
            val intent = Intent()
            intent.putExtra("return_data","哈哈哈");
            setResult(RESULT_OK,intent);
            finish()
        }
    }

    override fun onBackPressed() {
        super.onBackPressed()
        val intent = Intent()
        intent.putExtra("return_data","哈哈哈");
        setResult(RESULT_OK,intent);
        finish()
    }
}